package com.keepers.repair.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.keepers.repair.R;
import com.keepers.repair.activity.BaseActivity;
import com.keepers.repair.activity.TaskListActivity;
import com.keepers.repair.helper.IntentHelper;
import com.keepers.repair.helper.SpHelper;
import com.keepers.repair.model.UserModel;
import com.keepers.repair.view.TitleBar;

/**
 * auth aboom
 * date 2018/10/22
 */
public class TaskFragment extends BaseFragment {

    private boolean isImmersiveStatusBar;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof BaseActivity) {
            this.isImmersiveStatusBar = ((BaseActivity) context).isImmersiveStatusBar;
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = ff(R.layout.fragment_task);
        if (isImmersiveStatusBar) {
            f(view, R.id.status_bar).setVisibility(View.VISIBLE);
        }
        TitleBar titleBar = f(view, R.id.title_bar);
        titleBar.initializeHeaderNo("任务");
        f(view, R.id.task_today).setOnClickListener(v -> IntentHelper.goTaskList(getActivity(), TaskListActivity.TO_DAY));
        f(view, R.id.task_tomorrow).setOnClickListener(v -> IntentHelper.goTaskList(getActivity(), TaskListActivity.TO_TOMORROW));
        f(view, R.id.layout_report).setOnClickListener(v -> IntentHelper.goReport(getActivity()));
        UserModel loginUserInfo = SpHelper.getLoginUserInfo();
        if ("管理员".equals(loginUserInfo.RoleName)) {
            View maintenance = f(view, R.id.layout_maintenance);
            maintenance.setOnClickListener(v -> IntentHelper.goMaintenance(getActivity()));
            maintenance.setVisibility(View.VISIBLE);
        }
        if ("检修员".equals(loginUserInfo.RoleName)) {
            View myMaintenance = f(view, R.id.layout_my_maintenance);
            myMaintenance.setOnClickListener(v -> IntentHelper.goMyMaintenance(getActivity()));
            myMaintenance.setVisibility(View.VISIBLE);
        }
        return view;
    }
}
